package com.xh.demo.controller;

import com.xh.demo.mq.stream.DelayNoticeProducer;
import com.xh.demo.mq.stream.NoticeProducer;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wen
 * @apiNote TestStreamController
 * @since 2021-08-05
 */
@Api(tags = {"STREAM实现延时消息"})
@RestController
@RequestMapping("/stream")
public class TestStreamController {

    @Autowired
    private NoticeProducer noticeProducer;
    @Autowired
    private DelayNoticeProducer delayNoticeProducer;

    @ApiOperation(value = "普通交换机-发送普通消息")
    @GetMapping("/send/{msg}")
    public String send(@ApiParam(name = "msg", value = "消息内容", required = true) @PathVariable("msg") String msg) {
        noticeProducer.sendMsg(msg);
        return "SUCCESS";
    }

    @ApiOperation(value = "普通交换机-测试发送延时消息")
    @GetMapping("/test/send/{msg}/{time}")
    public String testSendDlx(@ApiParam(name = "msg", value = "消息内容", required = true) @PathVariable("msg") String msg,
                              @ApiParam(name = "time", value = "延时消费时间（ms）", required = true) @PathVariable("time") long time) {
        noticeProducer.testSendDlx(msg, time);
        return "SUCCESS";
    }

    @ApiOperation(value = "DLX交换机-发送延时消息")
    @GetMapping("/send/dlx/{msg}/{time}")
    public String sendDelayedMsg(@ApiParam(name = "msg", value = "消息内容", required = true) @PathVariable("msg") String msg,
                                 @ApiParam(name = "time", value = "延时消费时间（ms）", required = true) @PathVariable("time") long time) {
        delayNoticeProducer.sendDelayedMsg(msg, time);
        return "SUCCESS";
    }

    @ApiOperation(value = "DLX交换机-发送普通消息")
    @GetMapping("/send/normal/{msg}")
    public String sendNormalMsg(@ApiParam(name = "msg", value = "消息内容", required = true) @PathVariable("msg") String msg) {
        delayNoticeProducer.sendNormalMsg(msg);
        return "SUCCESS";
    }

}
